package com.weiadmin.dao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.weiadmin.common.PageParam;
import com.weiadmin.model.system.PostCategoryModel;
import com.weiadmin.model.system.PostModel;

public interface PostDao extends MPJBaseMapper<PostModel> {
    
    default Page<PostModel> getList(PageParam pageParam){

        Page<PostModel> pager = new Page<>(pageParam.getPage(), pageParam.getLimit());
//        QueryWrapper<PostModel> queryWrapper = new QueryWrapper<>();
//        queryWrapper.orderByDesc("id");
        MPJLambdaWrapper <PostModel> queryWrapper = new MPJLambdaWrapper<PostModel>()
                .selectAll(PostModel.class)
                .selectAs(PostCategoryModel::getName,"categoryName")
                .leftJoin(PostCategoryModel.class,PostCategoryModel::getId,PostModel::getCateId)
                ;
        return selectPage(pager, queryWrapper);
    }
}
